<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>接济单详情 - 监室管理系统</title>
    <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #3498db;
            --background: #f8f9fa;
            --accent-color: #e74c3c;
            --success-color: #2ecc71;
        }

        body {
            font-family: 'Segoe UI', system-ui, sans-serif;
            margin: 0;
            padding: 0;
            background-color: var(--background);
        }

        /* 导航栏样式 */
        .navbar {
            background-color: var(--primary-color);
            padding: 0;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .nav-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }

        .logo {
            color: white;
            font-size: 1.5em;
            font-weight: bold;
            padding: 15px 0;
            text-decoration: none;
        }

        .nav-links {
            display: flex;
            list-style: none;
            margin: 0;
            padding: 0;
        }

        .nav-links li {
            margin: 0;
            padding: 0;
        }

        .nav-links a {
            color: rgba(255,255,255,0.8);
            text-decoration: none;
            padding: 20px 15px;
            display: block;
            transition: all 0.3s;
            border-bottom: 3px solid transparent;
        }

        .nav-links a:hover, .nav-links a.active {
            color: white;
            border-bottom: 3px solid var(--secondary-color);
        }

        .user-controls {
            display: flex;
            align-items: center;
        }

        .content {
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .status-badge {
            padding: 5px 15px;
            border-radius: 20px;
            font-size: 0.9em;
            font-weight: bold;
        }
        
        .status-draft { background-color: #f8f9fa; color: #6c757d; }
        .status-pending { background-color: #fff3cd; color: #856404; }
        .status-printed { background-color: #d1ecf1; color: #0c5460; }
        .status-sent { background-color: #cce7ff; color: #004085; }
        .status-received { background-color: #d4edda; color: #155724; }
        .status-archived { background-color: #e2e3e5; color: #383d41; }
        
        .form-container {
            background: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
            padding: 30px;
            margin: 20px auto;
            max-width: 800px;
        }
        
        .header {
            border-bottom: 2px solid #f0f0f0;
            padding-bottom: 20px;
            margin-bottom: 30px;
        }
        
        .form-title {
            font-size: 1.8em;
            color: #333;
            margin-bottom: 10px;
        }
        
        .form-number {
            color: #666;
            font-size: 1.1em;
        }
        
        .section {
            margin-bottom: 25px;
        }
        
        .section-title {
            font-size: 1.2em;
            color: #444;
            border-left: 4px solid #3498db;
            padding-left: 10px;
            margin-bottom: 15px;
        }
        
        .info-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
        }
        
        .info-item {
            margin-bottom: 10px;
        }
        
        .info-label {
            font-weight: bold;
            color: #555;
            margin-bottom: 3px;
        }
        
        .info-value {
            color: #333;
        }
        
        .items-table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
        }
        
        .items-table th,
        .items-table td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: left;
        }
        
        .items-table th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        
        .timeline {
            display: flex;
            justify-content: space-between;
            margin: 30px 0;
            position: relative;
        }
        
        .timeline::before {
            content: '';
            position: absolute;
            top: 15px;
            left: 0;
            right: 0;
            height: 2px;
            background-color: #ddd;
            z-index: 1;
        }
        
        .timeline-item {
            text-align: center;
            position: relative;
            z-index: 2;
        }
        
        .timeline-dot {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            background-color: #ddd;
            margin: 0 auto 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
        }
        
        .timeline-dot.completed {
            background-color: #28a745;
        }
        
        .timeline-dot.current {
            background-color: #3498db;
        }
        
        .timeline-label {
            font-size: 0.9em;
            color: #666;
        }
        
        .timeline-time {
            font-size: 0.8em;
            color: #999;
        }
        
        .action-buttons {
            text-align: center;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        
        .btn-action {
            margin: 0 5px;
            padding: 10px 20px;
            border-radius: 5px;
            text-decoration: none;
            display: inline-block;
            transition: all 0.3s;
        }
        
        .btn-primary {
            background-color: #3498db;
            color: white;
            border: none;
        }
        
        .btn-success {
            background-color: #28a745;
            color: white;
            border: none;
        }
        
        .btn-warning {
            background-color: #ffc107;
            color: #212529;
            border: none;
        }
        
        .btn-secondary {
            background-color: #6c757d;
            color: white;
            border: none;
        }
        
        .btn-danger {
            background-color: #dc3545;
            color: white;
            border: none;
        }
        
        .btn-action:hover {
            opacity: 0.9;
            transform: translateY(-2px);
        }
        
        .page-title {
            margin-bottom: 20px;
            color: var(--primary-color);
        }
        
        .alert {
            margin-bottom: 15px;
            padding: 10px 15px;
            border-radius: 5px;
        }
        
        .alert-info {
            background-color: #e3f2fd;
            border-left: 4px solid #3498db;
        }
        
        .alert-success {
            background-color: #e8f5e9;
            border-left: 4px solid #2ecc71;
        }
        
        .alert-danger {
            background-color: #ffebee;
            border-left: 4px solid #e74c3c;
        }
        
        @media print {
            .no-print {
                display: none !important;
            }
            
            body {
                background: white;
                padding: 0;
                margin: 0;
            }
            
            .form-container {
                box-shadow: none;
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar">
        <div class="nav-container">
            <a href="/" class="logo">监室管理系统</a>
            <ul class="nav-links">
                <li><a href="/">首页</a></li>
                <li><a href="/rooms">房间管理</a></li>
                <li><a href="/relief_forms" class="active">接济管理</a></li>
                <li><a href="/medical">医疗辅助</a></li>
                <li><a href="/record">记录审计</a></li>
            </ul>
            <div class="user-controls">
                {% if current_user.is_authenticated %}
                <span style="color: white; margin-right: 15px;">
                    欢迎，{{ current_user.username }}
                    {% if current_user.user_type != 'normal' %}
                    <span style="background: #f39c12; color: white; padding: 3px 8px; border-radius: 3px; font-size: 0.8em; margin-left: 5px;">管理员</span>
                    {% else %}
                    <span style="background: #3498db; color: white; padding: 3px 8px; border-radius: 3px; font-size: 0.8em; margin-left: 5px;">普通用户</span>
                    {% endif %}
                </span>
                <a href="/logout" style="background: var(--accent-color); color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none;">
                    登出系统
                </a>
                {% else %}
                <a href="/login" style="background: var(--secondary-color); color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none; margin-right: 10px;">
                    登录
                </a>
                <a href="/register" style="background: var(--success-color); color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none;">
                    注册
                </a>
                {% endif %}
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="form-container">
            <!-- 头部信息 -->
            <div class="header-section">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h1 class="form-title">接济单详情</h1>
                        <p class="mb-0 text-muted">编号: {{ relief_form.form_id }}</p>
                    </div>
                    <span class="status-badge status-{{ relief_form.status|lower|replace(' ', '-') }}">
                        {{ relief_form.status }}
                    </span>
                </div>
            </div>

            <!-- 基本信息 -->
            <div class="info-section">
                <div class="info-row">
                    <span class="info-label">接收人:</span>
                    <span>{{ relief_form.recipient_name }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">开具人:</span>
                    <span>{{ relief_form.issuer_name }}</span>
                </div>
                <div class="info-row">
                    <span class="info-label">存入金额:</span>
                    <span>{{ "%.2f"|format(relief_form.total_value or 0) }} 元</span>
                </div>
                <div class="info-row">
                    <span class="info-label">物品清单:</span>
                    <span>{{ relief_form['items'] or '无' }}</span>
                </div>
            </div>


            <!-- 备注 -->
            {% if relief_form.notes %}
            <div class="info-row">
                <h5>备注</h5>
                <p>{{ relief_form.notes|replace('\n', '<br>')|safe }}</p>
            </div>
            {% endif %}

            <!-- 二维码 -->
            {% if relief_form.qr_code_hash and relief_form.status in ['已打印', '已寄出', '已签收'] %}
            <div class="qr-code-container">
                <h5>防伪二维码</h5>
                <div class="qr-code-placeholder">
                    <div>
                        <i class="bi bi-qr-code" style="font-size: 3em;"></i>
                        <p class="mb-0 mt-2">二维码区域</p>
                        <small class="text-muted">请在打印时生成</small>
                    </div>
                </div>
                <p class="text-muted mt-2">
                    <small>此二维码用于签收时验证接济单真伪</small>
                </p>
            </div>
            {% endif %}

            <!-- 时间线 -->
            <div class="info-row">
                <h5>处理时间线</h5>
                <div class="timeline">
                    <div class="row">
                        <div class="col-md-2 text-center">
                            <div class="badge bg-secondary">开具</div>
                            <div class="small text-muted mt-1">{{ relief_form.created_at.strftime('%m-%d %H:%M') }}</div>
                        </div>
                        <div class="col-md-2 text-center">
                            <div class="badge {{ 'bg-warning' if relief_form.status == '待审核' else 'bg-secondary' if relief_form.status in ['已打印', '已寄出', '已签收', '已归档'] else 'bg-light text-dark' }}">
                                审核
                            </div>
                            {% if relief_form.audited_at %}
                            <div class="small text-muted mt-1">{{ relief_form.audited_at.strftime('%m-%d %H:%M') }}</div>
                            {% endif %}
                        </div>
                        <div class="col-md-2 text-center">
                            <div class="badge {{ 'bg-info' if relief_form.status == '已打印' else 'bg-secondary' if relief_form.status in ['已寄出', '已签收', '已归档'] else 'bg-light text-dark' }}">
                                打印
                            </div>
                            {% if relief_form.printed_at %}
                            <div class="small text-muted mt-1">{{ relief_form.printed_at.strftime('%m-%d %H:%M') }}</div>
                            {% endif %}
                        </div>
                        <div class="col-md-2 text-center">
                            <div class="badge {{ 'bg-primary' if relief_form.status == '已寄出' else 'bg-secondary' if relief_form.status in ['已签收', '已归档'] else 'bg-light text-dark' }}">
                                寄出
                            </div>
                            {% if relief_form.sent_at %}
                            <div class="small text-muted mt-1">{{ relief_form.sent_at.strftime('%m-%d %H:%M') }}</div>
                            {% endif %}
                        </div>
                        <div class="col-md-2 text-center">
                            <div class="badge {{ 'bg-success' if relief_form.status == '已签收' else 'bg-secondary' if relief_form.status == '已归档' else 'bg-light text-dark' }}">
                                签收
                            </div>
                            {% if relief_form.received_at %}
                            <div class="small text-muted mt-1">{{ relief_form.received_at.strftime('%m-%d %H:%M') }}</div>
                            {% endif %}
                        </div>
                        <div class="col-md-2 text-center">
                            <div class="badge {{ 'bg-dark' if relief_form.status == '已归档' else 'bg-light text-dark' }}">
                                归档
                            </div>
                            {% if relief_form.archived_at %}
                            <div class="small text-muted mt-1">{{ relief_form.archived_at.strftime('%m-%d %H:%M') }}</div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>

            <!-- 操作按钮 -->
            <div class="action-buttons no-print">
                <button class="btn btn-secondary me-2" onclick="window.history.back()">
                    <i class="bi bi-arrow-left"></i> 返回
                </button>
                
                {% if current_user.role_id == 4 and relief_form.status == '待审核' %} <!-- 接济窗口角色 -->
                <button class="btn btn-primary me-2" onclick="printForm()">
                    <i class="bi bi-printer"></i> 打印
                </button>
                {% endif %}
                
                {% if current_user.role_id == 4 and relief_form.status == '已打印' %} <!-- 接济窗口角色 -->
                <button class="btn btn-success me-2" onclick="sendForm({{ relief_form.id }})">
                    <i class="bi bi-send"></i> 标记为已寄出
                </button>
                {% endif %}
                
                {% if current_user.role_id == 4 and relief_form.status == '已寄出' %} <!-- 接济窗口角色 -->
                <button class="btn btn-success me-2" onclick="receiveForm({{ relief_form.id }})">
                    <i class="bi bi-check2-square"></i> 标记为已签收
                </button>
                {% endif %}
            </div>
        </div>
    </div>

    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/bootstrap.bundle.min.js"></script>
    <script>
        // 打印功能
        function printForm() {
            window.print();
        }
        
        // 标记为已寄出
        function sendForm(formId) {
            if (confirm('确定要标记为已寄出吗？')) {
                $.ajax({
                    url: `/api/relief_forms/${formId}/send`,
                    method: 'PUT',
                    success: function(response) {
                        location.reload();
                    },
                    error: function(xhr, status, error) {
                        alert('操作失败: ' + xhr.responseText);
                    }
                });
            }
        }
        
        // 标记为已签收
        function receiveForm(formId) {
            if (confirm('确定要标记为已签收吗？')) {
                $.ajax({
                    url: `/api/relief_forms/${formId}/receive`,
                    method: 'PUT',
                    success: function(response) {
                        location.reload();
                    },
                    error: function(xhr, status, error) {
                        alert('操作失败: ' + xhr.responseText);
                    }
                });
            }
        }
    </script>
</body>
</html>

<style>
    /* 新设计导航栏样式 */
    .navbar {
        background-color: #2c3e50;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
        padding: 10px 20px;
    }

    .nav-links a {
        color: #ffffff;
        font-size: 1.1em;
        font-weight: bold;
        margin: 0 15px;
        text-decoration: none;
    }

    .nav-links a:hover, .nav-links a.active {
        color: #ff9800;
        text-decoration: underline;
    }

    /* 新设计表单容器样式 */
    .form-container {
        background: #ffffff;
        border-radius: 20px;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
        padding: 50px;
        margin: 30px auto;
        max-width: 900px;
    }

    .form-title {
        font-size: 2.5em;
        color: #333333;
        text-align: center;
        margin-bottom: 20px;
    }

    .status-badge {
        font-size: 1.2em;
        padding: 12px 25px;
        border-radius: 30px;
        background-color: #3498db;
        color: #ffffff;
        text-align: center;
    }

    /* 新设计时间线样式 */
    .timeline {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin: 50px 0;
    }

    .timeline::before {
        content: '';
        position: absolute;
        width: 4px;
        height: 100%;
        background-color: #ddd;
        left: 50%;
        transform: translateX(-50%);
    }

    .timeline-dot {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: #ff9800;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #ffffff;
        font-size: 1.2em;
        margin-bottom: 20px;
    }

    .timeline-label {
        font-size: 1.1em;
        color: #666666;
        margin-bottom: 10px;
    }

    .timeline-time {
        font-size: 1em;
        color: #999999;
    }
</style>
